﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Collections;
using Com.Crc.PoJo.Model.UserBoard;
using SnailGame.Utility.DataAccess;

namespace Com.Crc.ResManage.DAL.EquipManage
{
    public class BroadBandManageUserBoardDAL
    {
        DataBroker broker = new DataBroker();

        /// <summary>
        /// 新增宽带设备用户板信息
        /// </summary>
        /// <param name="data">model实体</param>
        /// <returns></returns>
        public bool AddWLANUserBoardData(WLANUserBoardEntity data)
        {
            string strSql = @" INSERT INTO TT_USERBOARD_WLAN(S_NAME,N_EXCHANGE_ID,N_CAP,N_TYPE,N_VLAN_S,N_VLAN_E,N_PORT_S,N_PORT_E,
                                           N_TREN_S,N_TREN_E)
                                    VALUES (''," + data.N_EXCHANGE_ID + "," + data.N_CAP + "," + data.N_TYPE + "," + data.N_VLAN_S + ","
                                           + data.N_VLAN_E + "," + data.N_PORT_S + "," + data.N_PORT_E + "," + data.N_TREN_S + ","
                                           + data.N_TREN_E + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 修改宽带设备用户板信息
        /// </summary>
        /// <param name="data">model实体</param>
        /// <returns></returns>
        public bool UpdateWLANUserBoardData(WLANUserBoardEntity data)
        {
            string strSql = @" UPDATE TT_USERBOARD_WLAN
                                  SET S_NAME = '', 
                                      N_EXCHANGE_ID = " + data.N_EXCHANGE_ID + @", 
                                      N_CAP = " + data.N_CAP + @",
                                      N_TYPE = " + data.N_TYPE + @", 
                                      N_VLAN_S = " + data.N_VLAN_S + @",
                                      N_VLAN_E = " + data.N_VLAN_E + @", 
                                      N_PORT_S = " + data.N_PORT_S + @",
                                      N_PORT_E = " + data.N_PORT_E + @", 
                                      N_TREN_S = " + data.N_TREN_S + @",
                                      N_TREN_E = " + data.N_TREN_E + @"
                                WHERE N_ID=" + data.N_ID;
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

       /// <summary>
        /// 查询宽带设备用户板信息
       /// </summary>
       /// <param name="strBranchID">分局ID</param>
       /// <param name="strOfficeID">局点ID</param>
       /// <param name="strEquipID">设备ID</param>
       /// <param name="strUserBoardID">用户板ID</param>
       /// <returns></returns>
        public DataTable QueryWLANUserBoardData(string strBranchID, string strOfficeID, string strEquipID,string strUserBoardID)
        {
            string strSql = @" SELECT a.N_ID,a.S_NAME,a.N_EXCHANGE_ID,a.N_CAP,a.N_TYPE,a.N_VLAN_S,a.N_VLAN_E,a.N_PORT_S,a.N_PORT_E,
                                      a.N_TREN_S,a.N_TREN_E
                                 FROM TT_USERBOARD_WLAN a
                           INNER JOIN TT_RESOURCE_WLAN b ON a.N_EXCHANGE_ID=b.N_ID
                                WHERE S_STATE='1' ";
            if (strBranchID != "")
            {
                strSql += " AND b.N_DEP_BRANCH_ID = " + strBranchID;
            }
            if (strOfficeID != "")
            {
                strSql += " AND b.N_SUBSTATION_ID = " + strOfficeID;
            }
            if (strEquipID != "")
            {
                strSql += " AND a.N_EXCHANGE_ID = " + strEquipID;
            }
            if (strUserBoardID != "")
            {
                strSql += " AND a.N_ID = " + strUserBoardID;
            }
            return broker.ExecuteQueryForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 删除设备下面的用户板
        /// </summary>
        /// <param name="wlanList"></param>
        /// <returns></returns>
        public bool DeleteWLANUserBoardData(ArrayList userboardList)
        {
            string strWlanID = "";
            for (int i = 0; i < userboardList.Count; i++)
            {
                strWlanID += userboardList[i] + ",";
            }
            strWlanID = strWlanID.Substring(0, strWlanID.Length - 1);
            string strSql = @"DELETE FROM TT_USERBOARD_WLAN WHERE N_ID IN (" + strWlanID + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }
    }
}
